/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package webservice;

import java.util.List;
import javax.ejb.EJB;
import javax.jws.WebService;
import javax.ejb.Stateless;
import javax.jws.Oneway;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import model.LivrosFacade;

/**
 *
 * @author Daniel
 */
@WebService(serviceName = "Livros")
@Stateless()
public class Livros {
    @EJB
    private LivrosFacade ejbRef;// Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Web Service Operation")
    
    @WebMethod(operationName = "getListaProduto")
     public List<model.Livros> getListaProduto() {
        return ejbRef.findAll();
    }
    
    @WebMethod(operationName = "getProduto")
    public model.Livros getProduto(@WebParam(name = "id") Object id) {
        return ejbRef.find(id);
    }

    @WebMethod(operationName = "setVenda")
    public boolean setVenda(@WebParam(name = "id") Object id, int qtde) {
        model.Livros l = ejbRef.find(id);
        
        if (l.getQuantidade()<qtde) {
            return false;
        }
        else {
            l.setQuantidade(l.getQuantidade()-qtde);
        }
        
        return true;
    }
    
    @WebMethod(operationName = "setCompra")
    public boolean setCompra(@WebParam(name = "id") Object id, int qtde) {
         model.Livros l = ejbRef.find(id);
        l.setQuantidade(l.getQuantidade()+qtde);
        return true;
    }
    
    
    /*
    @WebMethod(operationName = "create")
    @Oneway
    public void create(@WebParam(name = "entity") model.Livros entity) {
        ejbRef.create(entity);
    }

    @WebMethod(operationName = "edit")
    @Oneway
    public void edit(@WebParam(name = "entity") model.Livros entity) {
        ejbRef.edit(entity);
    }

    @WebMethod(operationName = "remove")
    @Oneway
    public void remove(@WebParam(name = "entity") model.Livros entity) {
        ejbRef.remove(entity);
    }

    @WebMethod(operationName = "find")
    public model.Livros find(@WebParam(name = "id") Object id) {
        return ejbRef.find(id);
    }

    @WebMethod(operationName = "findAll")
    public List<model.Livros> findAll() {
        return ejbRef.findAll();
    }

    @WebMethod(operationName = "findRange")
    public List<model.Livros> findRange(@WebParam(name = "range") int[] range) {
        return ejbRef.findRange(range);
    }

    @WebMethod(operationName = "count")
    public int count() {
        return ejbRef.count();
    }
    */
    
    
}
